/*
 * UserSubject.java
 *
 * Created on May 7, 2011, 2:57:29 PM
 */

package c0907m.group2.aitsm.gui;

import c0907m.group2.aitsm.core.db.SubjectDb;
import c0907m.group2.aitsm.core.db.UserDb;
import c0907m.group2.aitsm.core.db.UserSubjectDb;
import c0907m.group2.aitsm.core.entity.SubjectInfo;
import c0907m.group2.aitsm.core.entity.UserInfo;
import c0907m.group2.aitsm.gui.component.DefaultPanel;
import c0907m.group2.aitsm.gui.component.StatusBar;
import c0907m.group2.aitsm.util.Helper;
import c0907m.group2.aitsm.util.Settings;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author ISTC
 */
public class UserSubject extends DefaultPanel {
    public static final String DEFAULT_STATUS = "Manage which subject belongs to which user";
    public final Logger logger = Logger.getLogger(UserSubject.class.getName());
    private UserDb userDB;
    private StatusBar statusBar;
    private DefaultTableModel userModel;
    private DefaultTableModel subjectModel;

    public void setStatusBar(StatusBar sb) {
        this.statusBar = sb;
    }

    /**
     * Creates new form UserSubject
     */
    public UserSubject() {
        initComponents();
        statusBar = new StatusBar();
        loadUsersToTable();
        subjectModel = (DefaultTableModel) tblSubjectList.getModel();
        userModel = (DefaultTableModel) tblUserList.getModel();
        tableRowSorter();
    }

    @Override
    public void refresh() {
        loadUsersToTable();
        doReset();
    }

    public void doReset() {
        subjectModel.setRowCount(0);
    }

    @Override
    public void doUpdate() {
        List<Integer> idToUpdate = new ArrayList<Integer>();
        boolean checked;

        for (int i = 0; i < subjectModel.getRowCount(); i++) {
            checked = (Boolean) subjectModel.getValueAt(i, 3);
            if (checked)
                idToUpdate.add((Integer) subjectModel.getValueAt(i, 0));
        }

        int userId = (Integer) userModel.getValueAt(tblUserList.getSelectedRow(), 0);
        try {
            new UserSubjectDb().update(userId, idToUpdate);
            statusBar.setMessage("Update successful.", StatusBar.MESSAGE_TYPE);
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, null, ex);
            statusBar.setMessage("Update failed.", StatusBar.ERROR_TYPE);
        }
    }

    /**
     * Search user by Id
     */
    public void idSearch() {
        int getId;
        UserInfo result;
        userModel.setRowCount(0);

        try {
            getId = Integer.parseInt(txtSearchById.getText());
        } catch (NumberFormatException e) {
            new JOptionPane().showMessageDialog(
                    this,
                    "Wrong input format!",
                    "Message",
                    JOptionPane.ERROR_MESSAGE
            );
            return;
        }

        try {
            result = userDB.select(getId);
            if (result != null) {
                statusBar.setMessage("1 match(es) found.", StatusBar.MESSAGE_TYPE);

                userModel.addRow(new Object[]{
                        result.getId(),
                        result.getName(),
                        result.getDescription(),
                        result.isActive()
                });
            } else {
                statusBar.setMessage("No match found.", StatusBar.MESSAGE_TYPE);
            }
        } catch (SQLException e) {
            logger.log(Level.WARNING, e.getMessage());
            statusBar.setMessage("Search stopped.", StatusBar.ERROR_TYPE);
        }
    }

    /**
     * Search user by name
     */
    public void nameSearch() {
        String name = txtSearchByName.getText();
        List<UserInfo> result;
        userModel.setRowCount(0);
        try {
            result = userDB.select(name);
            if (result.size() != 0) {
                statusBar.setMessage(result.size() + " match(es) found.", StatusBar.MESSAGE_TYPE);

                for (UserInfo u : result)
                    userModel.addRow(new Object[]{
                            u.getId(),
                            u.getName(),
                            u.getDescription(),
                            u.isActive()
                    });
            } else {
                statusBar.setMessage("No match found.", StatusBar.MESSAGE_TYPE);
            }
        } catch (SQLException e) {
            logger.log(Level.WARNING, e.getMessage());
            statusBar.setMessage("Search stopped.", StatusBar.ERROR_TYPE);
        }
    }

    /**
     * Load all Users from database to table when initialize
     */
    private void loadUsersToTable() {
        userModel = (DefaultTableModel) tblUserList.getModel();
        userModel.setRowCount(0);
        userDB = new UserDb();
        List<UserInfo> UserList = null;
        try {
            UserList = userDB.select();
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, ex.getMessage());
            statusBar.setMessage("Unable to load data.", StatusBar.WARNING_TYPE);
        }

        for (UserInfo r : UserList) {
            if (r.isActive())
                userModel.addRow(new Object[]{
                        r.getId(),
                        r.getName(),
                        r.getDescription(),
                        r.isActive()
                });
        }
    }

    /**
     * Load all active subject to table when choosing a user
     */
    private void loadSubjectsToTable() {
        subjectModel = (DefaultTableModel) tblSubjectList.getModel();
        subjectModel.setRowCount(0);

        int userId = (Integer) userModel.getValueAt(tblUserList.getSelectedRow(), 0);
        try {
            List<SubjectInfo> sbjList = new SubjectDb().select();
            List<Integer> existList = new UserSubjectDb().select(userId, UserSubjectDb.USER);

            for (SubjectInfo s : sbjList) {
                if (!s.isActive())
                    continue;

                boolean isExisted = false;

                if (!existList.isEmpty()) {
                    for (int e : existList) {
                        if (s.getId() == e) {
                            subjectModel.addRow(new Object[]{
                                    s.getId(),
                                    s.getName(),
                                    s.getDescription(),
                                    true
                            });
                            isExisted = true;
                            break;
                        }
                    }
                }

                if (!isExisted) {
                    subjectModel.addRow(new Object[]{
                            s.getId(),
                            s.getName(),
                            s.getDescription(),
                            false
                    });
                }
            }
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, ex.getSQLState());
        }
    }

    /**
     * Make a table row-sort-able
     */
    private void tableRowSorter() {
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(subjectModel);
        tblSubjectList.setRowSorter(sorter);
        sorter = new TableRowSorter<TableModel>(userModel);
        tblUserList.setRowSorter(sorter);
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel4 = new javax.swing.JLabel();
        pnUserInfo = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblUserList = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        pnSubjectList = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblSubjectList = new javax.swing.JTable();
        btnRefresh = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtSearchByName = new javax.swing.JTextField();
        btnSearchByName = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        btnDropDown = new javax.swing.JButton();
        pnToggle = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtSearchById = new javax.swing.JTextField();
        btnSearchById = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 16));
        jLabel4.setForeground(new java.awt.Color(0, 102, 255));
        jLabel4.setText("MANAGE USER-SUBJECT RELATIONSHIP");

        pnUserInfo.setBackground(new java.awt.Color(255, 255, 255));
        pnUserInfo.setBorder(javax.swing.BorderFactory.createTitledBorder("User list"));
        pnUserInfo.setPreferredSize(new java.awt.Dimension(452, 219));

        tblUserList.setModel(new DefaultTableModel(
                new Object[][]{

                },
                new String[]{
                        "ID", "Name", "Description"
                }
        ) {
            Class[] types = new Class[]{
                    Integer.class, String.class, String.class
            };
            boolean[] canEdit = new boolean[]{
                    false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        tblUserList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblUserListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblUserList);
        tblUserList.getColumnModel().getColumn(0).setPreferredWidth(5);

        jLabel1.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel1.setText("Select an user to display all subjects that he/she is handling:");

        javax.swing.GroupLayout pnUserInfoLayout = new javax.swing.GroupLayout(pnUserInfo);
        pnUserInfo.setLayout(pnUserInfoLayout);
        pnUserInfoLayout.setHorizontalGroup(
                pnUserInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnUserInfoLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(pnUserInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 391, Short.MAX_VALUE)
                                        .addComponent(jLabel1))
                                .addContainerGap())
        );
        pnUserInfoLayout.setVerticalGroup(
                pnUserInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnUserInfoLayout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())
        );

        pnSubjectList.setBackground(new java.awt.Color(255, 255, 255));
        pnSubjectList.setBorder(javax.swing.BorderFactory.createTitledBorder("Subject list"));

        tblSubjectList.setModel(new DefaultTableModel(
                new Object[][]{

                },
                new String[]{
                        "ID", "Name", "Description", ""
                }
        ) {
            Class[] types = new Class[]{
                    Integer.class, String.class, String.class, Boolean.class
            };
            boolean[] canEdit = new boolean[]{
                    false, false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane2.setViewportView(tblSubjectList);
        tblSubjectList.getColumnModel().getColumn(1).setPreferredWidth(100);
        tblSubjectList.getColumnModel().getColumn(2).setPreferredWidth(100);
        tblSubjectList.getColumnModel().getColumn(3).setPreferredWidth(10);

        javax.swing.GroupLayout pnSubjectListLayout = new javax.swing.GroupLayout(pnSubjectList);
        pnSubjectList.setLayout(pnSubjectListLayout);
        pnSubjectListLayout.setHorizontalGroup(
                pnSubjectListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnSubjectListLayout.createSequentialGroup()
                                .addContainerGap(23, Short.MAX_VALUE)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 391, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20))
        );
        pnSubjectListLayout.setVerticalGroup(
                pnSubjectListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnSubjectListLayout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
                                .addGap(25, 25, 25))
        );

        btnRefresh.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/refresh-16.gif"));
        btnRefresh.setText("Refresh");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        btnUpdate.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/update-16.png"));
        btnUpdate.setText("Update");
        btnUpdate.setMaximumSize(new java.awt.Dimension(71, 23));
        btnUpdate.setMinimumSize(new java.awt.Dimension(71, 23));
        btnUpdate.setPreferredSize(new java.awt.Dimension(71, 23));
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Search for user"));
        jPanel2.setMaximumSize(new java.awt.Dimension(452, 219));
        jPanel2.setMinimumSize(new java.awt.Dimension(452, 219));

        jLabel5.setText("Search by name:");

        btnSearchByName.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/search-16.png"));
        btnSearchByName.setText("Search");
        btnSearchByName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchByNameActionPerformed(evt);
            }
        });

        jLabel6.setText("Advance search");

        btnDropDown.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/dropDown_icon.png"));
        btnDropDown.setBorderPainted(false);
        btnDropDown.setContentAreaFilled(false);
        btnDropDown.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnDropDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDropDownActionPerformed(evt);
            }
        });

        pnToggle.setBackground(new java.awt.Color(255, 255, 255));

        jLabel7.setText("Search by ID:");

        btnSearchById.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/search-16.png"));
        btnSearchById.setText("Search");
        btnSearchById.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchByIdActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnToggleLayout = new javax.swing.GroupLayout(pnToggle);
        pnToggle.setLayout(pnToggleLayout);
        pnToggleLayout.setHorizontalGroup(
                pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnToggleLayout.createSequentialGroup()
                                .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel7)
                                        .addGroup(pnToggleLayout.createSequentialGroup()
                                                .addComponent(txtSearchById, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnSearchById)))
                                .addContainerGap(31, Short.MAX_VALUE))
        );
        pnToggleLayout.setVerticalGroup(
                pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnToggleLayout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtSearchById, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnSearchById, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(pnToggle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addComponent(txtSearchByName, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnSearchByName))
                                        .addComponent(jLabel5)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addComponent(btnDropDown, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(4, 4, 4)
                                                .addComponent(jLabel6)))
                                .addContainerGap(67, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtSearchByName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnSearchByName, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabel6))
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addGap(8, 8, 8)
                                                .addComponent(btnDropDown, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pnToggle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel4)
                                                        .addGroup(layout.createSequentialGroup()
                                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, 0, 427, Short.MAX_VALUE)
                                                                        .addComponent(pnUserInfo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 427, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(pnSubjectList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                        .addGroup(layout.createSequentialGroup()
                                                .addGap(353, 353, 353)
                                                .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(42, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGap(32, 32, 32)
                                .addComponent(jLabel4)
                                .addGap(28, 28, 28)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(pnSubjectList, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                .addComponent(pnUserInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(36, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void tblUserListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblUserListMouseClicked
        loadSubjectsToTable();
    }//GEN-LAST:event_tblUserListMouseClicked

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        refresh();
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        doUpdate();
    }//GEN-LAST:event_btnUpdateActionPerformed

    private void btnSearchByNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchByNameActionPerformed
        nameSearch();
    }//GEN-LAST:event_btnSearchByNameActionPerformed

    private void btnDropDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDropDownActionPerformed
        Helper.toggle(pnToggle);
    }//GEN-LAST:event_btnDropDownActionPerformed

    private void btnSearchByIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchByIdActionPerformed
        idSearch();
    }//GEN-LAST:event_btnSearchByIdActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDropDown;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnSearchById;
    private javax.swing.JButton btnSearchByName;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel pnSubjectList;
    private javax.swing.JPanel pnToggle;
    private javax.swing.JPanel pnUserInfo;
    private javax.swing.JTable tblSubjectList;
    private javax.swing.JTable tblUserList;
    private javax.swing.JTextField txtSearchById;
    private javax.swing.JTextField txtSearchByName;
    // End of variables declaration//GEN-END:variables


}
